<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        //用户
        Schema::create('system_users', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('uuid')->index()->default('');
            $table->string('no')->index()->unique()->comment('编号');
            $table->string('nickname')->nullable()->comment('昵称');
            $table->string('username')->nullable();
            $table->string('phone')->nullable()->unique();
            $table->string('email')->nullable()->unique();
            $table->string('password')->nullable();
            $table->bigInteger('parent_id')->default(0)->unsigned();
            $table->decimal('wallet',8,2)->default(0)->comment('钱包');
            $table->decimal('integral',8,2)->default(0)->comment('积分');

            # info
            $table->string('openid')->nullable()->comment('微信id');
            $table->string('avatar_url')->comment('')->nullable();
            $table->string('province')->comment('')->nullable();
            $table->string('city')->comment('')->nullable();
            $table->integer('gender')->comment('1男 2女')->nullable();
            # 身份证；
            $table->string('national_idnumber')->comment('国家身份号')->nullable();
            # 登录记录
            $table->timestamp('expire_at')->nullable();
            $table->timestamp('last_login')->nullable();

            # 经纬度
            $table->string('longitude')->default('')->comment('经度');
            $table->string('latitude')->default('')->comment('纬度');

            # 等级
            $table->integer('type')->default(1)->comment('用户类型 普通用户，');
            $table->integer('ratio')->default(0)->comment('比例%');
            $table->integer('level')->default(1)->comment('等级');
            $table->integer('distribution_level')->default(1)->comment('分销等级');
            $table->integer('audit_status')->default(1)->comment('审核状态');
            $table->string('remark')->default('')->comment('备注');
            $table->text('remember_token')->nullable();
            $table->timestamps();

        });

        // 用户文件
        Schema::create('user_file', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('用户id');
            $table->string('file_type')->default('file')
                ->comment('front_idcard_picture,
            back_idcard_picture,apply_file 数据可来自参数表');
            $table->string('file_url')->default('')->comment('文档地址');
            $table->timestamps();
        });


        // 积分记录
        Schema::create('user_integralrecord', function (Blueprint $table) {
            $table->integer('user_id')->comment('用户id')->nullable();
            $table->string('content')->default(0)->comment('内容');
            $table->integer('number')->nullable()->comment('变动数量');
            $table->integer('direction')->default(1)->comment('变动方向 1入 2出');
            $table->timestamps();
        });

        //钱包记录
        Schema::create('user_walletrecord', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('用户id')->nullable();
            $table->string('content')->default('')->comment('内容');
            $table->decimal('money',8,2)->nullable()->comment('变动金额');
            $table->integer('direction')->default(1)->comment('变动方向 1入 2出');
            $table->decimal('remaining_amount',8,2)->comment('余额');
            $table->decimal('before_amount')->comment('变动前的金额');
            $table->string('type')->default('default')->comment('order,curser,.. 数据类型，订单参数的，分享产生的...');
            $table->integer('type_id')->default(0)->comment('类型对应模型id 如订单id, 提现id');
            $table->timestamps();
        });

        //提现单 --提现完成 插入 钱包记录；
        Schema::create('withdrawal_cash', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('用户id')->nullable();
            $table->string('withdrawal_number')->comment('提现单号')->nullable();
            $table->string('content')->default('')->comment('内容');
            $table->string('remark')->default('')->comment('备注');
            $table->string('withdrawal_type')->default('wechat')->comment('提现到账方式');
            $table->decimal('money',8,2)->nullable()->comment('变动数量');
            $table->integer('status')->default(1)->comment('1处理中， 2 已打款，3打款失败，4 已驳回');
            $table->timestamps();
        });


        //助力提醒记录推广动态；记录  ；
        Schema::create('user_promotdynamics', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('用户id')->nullable();
            $table->integer('order_id')->default(0)->comment('订单id 状态关联订单状态 ');
            $table->integer('order_number')->default(0)->comment('订单号');
            $table->timestamp('order_created_at')->comment('创建时间');
            $table->string('remark')->nullable()->comment('备注 产品');
            $table->timestamps();
        });


        // 用户优惠券
        Schema::create('user_coupon',function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('用户id')->nullable();
            $table->integer('coupon_id')->comment('优惠券id');
            $table->timestamp('use_at')->comment('使用时间')->nullable();
            $table->timestamps();
        });

        // 分享 点击记录 --唯一主键 注意
        Schema::create('user_sharenotice',function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id')->comment('点击-用户id')->nullable();
            $table->integer('share_user_id')->comment('分享用户')->nullable();
            $table->string('content')->comment('内容')->nullable();
            $table->date('add_date')->nullable()->comment('添加日期');
            $table->timestamps();
            $table->unique(['user_id','share_user_id']);
        });

        //通知
        Schema::create('user_notice', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id');
            $table->integer('type_id')->nullable();
            $table->string('content')->comment('内容')->nullable();
            $table->string('type')->default('system')->comment('system, share, wallet');
            $table->timestamps();
        });

        // 签到 记录；
        Schema::create('user_checkin', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->integer('user_id');
            $table->date('add_date')->nullable()->comment('添加日期');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}
